import { login } from "../../utils/asyncWx.js";
import { request } from "../../request/index.js";

Page({
  data: {
    
  },
  //options(Object)
  onLoad: function(options){
    
  },
  async handleGetUserInfo(e){
    try {
      //1 获取用户信息
    const {encryptedData,rawData,iv,signature}=e.detail;
    //2 获取小程序登录成功后的code
    const {code}=await login();
    //3 将参数封装到一个属性中
    const loginParams={encryptedData,rawData,iv,signature,code};
    //4 调用封装的request方法
    //const {token}=await request({url:"/users/wxlogin",data:loginParams,method:"POST"});
    //console.log(res);//没有企业账号无法获取成功的
    //5 把token存入缓存中，同时跳转回上一个页面
    const token={
      user_name:"死神",
      token:"abcd",
      user_sex:"男",
    }
    wx.setStorageSync("token", token);
    wx.navigateBack({
      delta: 1
    });
    } catch (error) {
      console.log(error);
    }
  }
});
